package hibernate.method;

import hibernate.method.interfaces.RecommendationMethodsInterface;
import hibernate.model.GamesRecommendation;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

public class RecommendationMethods implements RecommendationMethodsInterface{

	@Override
	public void createGameRecommendation(SessionFactory sessionFactory,
			Session session, int user_id, int game_id, double similarity) {
		GamesRecommendation gr = new GamesRecommendation();
		gr.setGame_id(game_id);
		gr.setUser_id(user_id);
		gr.setSimilarity(similarity);
		session.save(gr);
	}

	

	@SuppressWarnings("unchecked")
	@Override
	public List<GamesRecommendation> listAllRecommendationsForUser(
			SessionFactory sessionFactory, Session session, int user_id) {
		Criteria cr = session.createCriteria(GamesRecommendation.class);
		cr.add(Restrictions.eq("user_id", user_id));
		return cr.list();
	}



	@Override
	public void deleteGameRecommendation(SessionFactory sessionFactory,
			Session session, GamesRecommendation gr) {
		session.delete(gr);
		
	}



	@Override
	public GamesRecommendation idToGameRecommendation(
			SessionFactory sessionFactory, Session session,
			int gamerecommendation_id) {
		Object object = session.load(GamesRecommendation.class, gamerecommendation_id);
		GamesRecommendation msg = (GamesRecommendation) object;
		return msg;
	}

}
